package jsu.xxy.coffee3.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jsu.xxy.coffee3.domain.RegisterRequest;
import jsu.xxy.coffee3.mapper.StaffsMapper;
import jsu.xxy.coffee3.service.RegisterRequestService;
import jsu.xxy.coffee3.mapper.RegisterRequestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 张从轩
* @description 针对表【register_request(注册请求信息表)】的数据库操作Service实现
* @createDate 2023-06-03 06:43:10
*/
@Service
public class RegisterRequestServiceImpl extends ServiceImpl<RegisterRequestMapper, RegisterRequest>
implements RegisterRequestService{
    @Autowired
    RegisterRequestMapper registerRequestMapper;
    @Autowired
    StaffsMapper staffsMapper;

    @Override
    public Page<RegisterRequest> getAllInform(Integer pageNo, Integer pageSize) {
        Page<RegisterRequest> page = new Page<>(pageNo, pageSize);
        registerRequestMapper.selectPage(page, null);
        return page;
    }

    @Override
    public Boolean agreeEmployee(String phone) {
        RegisterRequest registerRequest = registerRequestMapper.selectByphone_number(phone);
        QueryWrapper<RegisterRequest> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phonenumber",phone);
        registerRequestMapper.delete(queryWrapper);
        return staffsMapper.insertNoId(registerRequest) > 0;
    }

    @Override
    public Boolean disagreeEmployee(String phone) {
        RegisterRequest registerRequest = registerRequestMapper.selectByphone_number(phone);
        QueryWrapper<RegisterRequest> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phonenumber",phone);
        return registerRequestMapper.delete(queryWrapper)>0;
    }

    @Override
    public Integer agreeEmployeeList(List<String> phones) {
        for(String s : phones){
            System.out.println(s);
        }
        int ans = 0;
        QueryWrapper<RegisterRequest> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("phonenumber",phones);
        List<RegisterRequest> registerRequest = registerRequestMapper.selectList(queryWrapper);
        for(RegisterRequest r : registerRequest){
            System.out.println(r);
            ans += staffsMapper.insertNoId(r);
        }
        registerRequestMapper.delete(queryWrapper);
        return ans;
    }


}
